import { BaseWindow } from "../../../component/window/BaseWindow";
import { ILayer } from "../../../mvc/interfaces/ILayer";
import { Language } from "../../../../extend/language/Language";
import { ResFileConst } from "../../resource/ResFileConst";
import { PetIslandUtil } from "./PetIslandUtil";
import { MsgManager } from "../../manager/MsgManager";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { SPetInfo } from "../../../../Message/Game/SPetInfo";
import { ObjCreate } from "../common/ObjCreate";
import { ImagesConst } from "../../resource/ImagesConst";
import { PetComboBoxItemCellRender } from "../pet/changeModel/PetComboBoxItemCellRender";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { LoaderHelp } from "../../../common/display/LoaderHelp";
import { GComboBox } from "../../../../com/mui/controls/GComboBox";
import { GLoadedButton } from "../../../../com/mui/controls/GLoadedButton";
import { GButton } from "../../../../com/mui/controls/GButton";
import { GTextFiled } from "../../../../com/mui/controls/GTextFiled";
type int = number;
//class PetIslandApplyPanel
    
    export  class PetIslandApplyPanel extends BaseWindow
    {
        constructor(arg1: ILayer=null)
        {
            super(arg1);
            setSize(704, 487);
            titleHeight = 26;
            title = Language.getString(28100);
            return;
        }

        /* internal  */onOperateBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._operateBtn.styleName != ResFileConst.PetIslandApplyJoinGuildBtn) 
            {
                if (this._operateBtn.styleName == ResFileConst.PetIslandApplyJoinBtn || this._operateBtn.styleName == ResFileConst.PetIslandApplyBtn) 
                {
                    if (!PetIslandUtil.canApply) 
                    {
                        MsgManager.showRollTipsMsg(Language.getString(28257));
                        return;
                    }
                    if (this._petListComBo.selectedItem && this._petListComBo.selectedItem.value) 
                    {
                        Dispatcher.dispatchEvent(new DataEvent(EventName.PetIslandApply, SPetInfo(this._petListComBo.selectedItem.value).uid));
                    }
                    else 
                    {
                        MsgManager.showRollTipsMsg(Language.getString(28206));
                    }
                }
            }
            else 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.OpenGuildWindow));
            }
            return;
        }

        /* internal  */onPetComboxChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            this._petListComBo.selectedIndex;
            return;
        }

        /* internal  */onShowListHandler(arg1: Object /* flash.events.TextEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.PetIslandApplyInfoShow));
            return;
        }

        /* internal  */onViewBtnClickHandler(arg1: Object /* flash.events.Event */): void
        {
            var loc1=null;
            var loc2=null;
            if (this._petListComBo.selectedItem) 
            {
                loc2 = this._petListComBo.selectedItem.value;
            }
            if (loc2 && !(loc2.uid == "")) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.PetShowInfo, loc2));
            }
            return;
        }

        public setPetListComBo(): void
        {
            var loc1=this._petListComBo.selectedIndex;
            this._petListComBo.dataProvider = PetIslandUtil.petComboDp;
            this._petListComBo.selectedIndex = loc1;
            return;
        }

        public set petListLabel(arg1: int)
        {
            this._listTxt.htmlText = Language.getStringByParam(28104, arg1);
            return;
        }

        public set applyPet(arg1: int)
        {
            PetIslandUtil.setSelectPet(this._petListComBo, arg1);
            return;
        }

        public set operateBtnStyleName(arg1: string)
        {
            if (arg1 != "") 
            {
                this._operateBtn.styleName = arg1;
                this._operateBtn.filterEnabled = true;
            }
            else 
            {
                this._operateBtn.styleName = ResFileConst.PetIslandApplyJoinBtn;
                this._operateBtn.filterEnabled = false;
            }
            return;
        }

        /* internal  */onResCompl(): void
        {
            pushUIToDisposeVec(ObjCreate.createGBitmap(ImagesConst.PetIslandApplyPlayText, 188, 100, this));
            pushUIToDisposeVec(ObjCreate.createGBitmap(ImagesConst.PetIslandApplyJoinText, 188, 256, this));
            pushUIToDisposeVec(ObjCreate.createGBitmap(ImagesConst.PetIslandApplyPetSelectText, 286, 302, this));
            pushUIToDisposeVec(ObjCreate.createGBitmap(ImagesConst.PetIslandApplyTextOne, 76, 445, this));
            pushUIToDisposeVec(ObjCreate.createGBitmap(ImagesConst.PetIslandApplyTextTwo, 164, 445, this));
            pushUIToDisposeVec(ObjCreate.createGBitmap(ImagesConst.PetIslandApplyArrows, 236, 449, this));
            pushUIToDisposeVec(ObjCreate.createGBitmap(ImagesConst.PetIslandApplyTextThree, 303, 445, this));
            pushUIToDisposeVec(ObjCreate.createGBitmap(ImagesConst.PetIslandApplyArrows, 375, 449, this));
            pushUIToDisposeVec(ObjCreate.createGBitmap(ImagesConst.PetIslandApplyTextFour, 441, 445, this));
            pushUIToDisposeVec(ObjCreate.createGBitmap(ImagesConst.PetIslandApplyArrows, 513, 449, this));
            pushUIToDisposeVec(ObjCreate.createGBitmap(ImagesConst.PetIslandApplyTextFive, 577, 445, this));
            return;
        }

        public /* override */ show(arg1: int=0, arg2: int=0): void
        {
            super.show(arg1, arg2);
            this.setPetListComBo();
            return;
        }

        public /* override */ hide(): void
        {
            super.hide();
            this.petListLabel = 0;
            this._petListComBo.selectedIndex = -1;
            return;
        }

        protected /* override */ createDisposedChildrenImpl(): void
        {
            super.createDisposedChildrenImpl();
            pushUIToDisposeVec(ObjCreate.createGImageBitmap(ImagesConst.PetIslandApplyBg, 18, 38, this));
            this._petListComBo = ObjCreate.createGComboBox(360, 300, 155, 25, null, this);
            this._petListComBo.selectedIndex = -1;
            this._petListComBo.prompt = Language.getString(28103);
            this._petListComBo.dropdown.setStyle("cellRenderer", PetComboBoxItemCellRender);
            this._operateBtn = ObjCreate.createGLoadedButton("", 388, 340, 97, 50, this);
            this._operateBtn.configEventListener(flash.events.MouseEvent.CLICK, this.onOperateBtnClickHandler);
            this._viewBtn = ObjCreate.createGButton("", 522, 294, 59, 32, this, "PetCpnViewButton");
            this._viewBtn.configEventListener(flash.events.MouseEvent.CLICK, this.onViewBtnClickHandler);
            this._listTxt = ObjCreate.createTextField("", 390, 398, 140, 20, this);
            this._listTxt.configEventListener(flash.events.TextEvent.LINK, this.onShowListHandler);
            this._listTxt.htmlText = Language.getStringByParam(28104, 0);
            pushUIToDisposeVec(ObjCreate.createGTextField(Language.getString(28101), 230, 60, 500, 20, this, GlobalStyle._textFormat2));
            var loc1=ObjCreate.createGTextField("", 213, 135, 450, 110, this, GlobalStyle.setTextFormatLeading(GlobalStyle._textFormat1, 5));
            loc1.wordWrap = true;
            loc1.multiline = true;
            loc1.htmlText = Language.getString(28106);
            pushUIToDisposeVec(loc1);
            LoaderHelp.addResCallBack(ResFileConst.PetIslandApply, this.onResCompl);
            return;
        }

        protected /* override */ disposeImpl(arg1: Boolean=true): void
        {
            super.disposeImpl(arg1);
            this._petListComBo.dispose(arg1);
            this._operateBtn.dispose(arg1);
            this._viewBtn.dispose(arg1);
            this._listTxt.dispose(arg1);
            return;
        }

        /* internal */ /* var */_petListComBo: GComboBox;

        /* internal */ /* var */_operateBtn: GLoadedButton;

        /* internal */ /* var */_viewBtn: GButton;

        /* internal */ /* var */_listTxt: GTextFiled;
    }
